import { handleActions } from 'redux-actions';
import { GET_ADMINS, SET_CUR_PAGE, SET_EACH_PAGE } from '../types';
import _ from 'lodash';
const initData = {
    curPage: 1,//当前页
    eachPage: 10,//每页显示的条数
    total: 0,//总条数
    maxPage: 0,//总页数
    rows: []//当前页的数据
}
export const adminsData = handleActions({
    [GET_ADMINS]: (state, { payload }) => {
        const { total, maxPage, rows } = payload;
        return _.assign({}, state, {
            total, maxPage, rows
        })
    },
    [SET_CUR_PAGE]: (state, { payload }) => {
        const { curPage } = payload;
        const $state = _.clone(state);
        $state.curPage = curPage;
        return $state
    },
    [SET_EACH_PAGE]: (state, { payload }) => {
        const { eachPage } = payload;
        const $state = _.clone(state);
        $state.eachPage = eachPage;
        $state.rows = [];
        return $state
    }
}, initData)